import time
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By

from common.base import Base


class Order_page(Base):
    def next_page(self):
        i = 1
        while i <= 10:
            self.click((By.XPATH, '//*[@id="page-link"]/a[3]'))
            time.sleep(0.5)
            i += 1

    # 向下翻页

    def previous_page(self):
        i = 1
        while i <= 10:
            self.click((By.XPATH, '//*[@id="page-link"]/a[2]'))
            time.sleep(0.5)
            i += 1

    # 像前翻页

    def home_page(self):
        self.click((By.XPATH, '//*[@id="page-link"]/a[1]'))

    def Last_page(self):
        self.click((By.XPATH, '//*[@id="page-link"]/a[4]'))
        time.sleep(1)

    def search_frame(self):
        self.frame((By.ID, 'main-frame'))

    def view_login(self):
        self.click((By.XPATH, '//*[@href="order.php?act=info&order_id=530"]'))
        time.sleep(1)

    def order_list(self):
        self.click((By.XPATH, '//*[@id="sub-menu-02_order_list"]/a'))

    def order_inquiry(self):
        self.click((By.XPATH, '//*[@href="order.php?act=order_query"]'))
        time.sleep(1)

    def order_number(self, number='2022070712476'):
        self.send_keys((By.ID, 'order_sn'), number)
        # 订单栏输入

    def search_button(self):
        self.click((By.CLASS_NAME, 'button'))
        # 点击搜索按钮

    def return_(self):
        self.click((By.XPATH, '//*[@href="order.php?act=list&uselastfilter=1"]'))
        # 点击返回订单列表

    def consignee(self):
        self.send_keys((By.ID, 'consignee'), '车车')
        # 填写收货人

    def advanced_search(self):
        self.click((By.XPATH, '//*[contains(@class,"btn-search")]'))
        # 点击高级按钮

    def combined_search(self):
        self.driver.execute_script("document.body.style.transform='scale(0.9)'")
        self.send_keys((By.XPATH, '//*[@id="order_sn" and @size="30"]'), '2022070672787')  # 输入高级搜索栏中订单号
        self.send_keys((By.XPATH, '//*[@id="email" and @size="30"]'), '123456789@qq.com')  # 输入高级搜索栏中邮箱
        self.send_keys((By.XPATH, '//*[@id="user_name" and @size="20"]'), 'hello1')  # 输入高级搜索栏中购货人
        self.send_keys((By.XPATH, '//*[@id="address" and @size="20"]'), '湖北省武汉市武昌')  # 输入高级搜索栏中地址
        self.send_keys((By.XPATH, '//*[@id="tel" and @size="20"]'), '12345678912')  # 输入高级搜索栏中电话
        self.send_keys((By.XPATH, '//*[@id="consignee" and @size="20"]'), '车车')  # 输入高级搜索栏中收货人
        self.order_status((By.ID, 'selCountries'), '1')
        time.sleep(0.5)
        self.order_status((By.ID, 'selProvinces'), '18')
        time.sleep(0.5)
        self.order_status((By.ID, 'selCities'), '204')
        time.sleep(0.5)
        self.order_status((By.ID, 'selDistricts'), '2139')
        time.sleep(0.5)
        self.order_status((By.ID, 'select4'), '5')
        self.order_status((By.ID, 'select9'), '1')
        self.order_status((By.ID, 'select11'), '0')
        self.order_status((By.ID, 'select10'), '0')

    def test(self):
        return self.get_element_text((By.XPATH, '/html/body/form/div[1]/table/tbody/tr[3]/td[2]'))
        # 获取订单号

    def test1(self):
        return self.get_element_text((By.XPATH, '/html/body/form/div[1]/table/tbody/tr[17]/td[2]'))
        # 获取收货人

    def test2(self):
        return self.get_element_text((By.XPATH, '/html/body/form/div[1]/table/tbody/tr[19]/td[2]'))
    # 获取电话

    def test3(self):
        return self.get_element_text((By.XPATH, '/html/body/form/div[1]/table/tbody/tr[4]/td[2]'))
    # 获取收货人

    def test4(self):
        return self.get_element_text((By.XPATH,'/html/body/form/div[1]/table/tbody/tr[18]/td[2]'))
    # 获取地址

    def test5(self):
        return self.get_element_text((By.XPATH,'/html/body/form/div[1]/table/tbody/tr[17]/td[4]'))
    # 获取邮箱

    def calendar(self):
        self.click((By.XPATH, '//*[@id="start_time_btn"]/img'))
        self.dou_ble((By.XPATH, '/html/body/div[5]/table/tbody/tr[2]/td[4]'))
        time.sleep(2)
        # 定位日历

    def query(self):
        self.click((By.ID, 'query'))

    def reset(self):
        self.click((By.XPATH, '//*[@id="panelQuery"]/div[3]/input[2]'))

    def quit1(self):
        self.quit()
